import { Config } from './Config'
import { Map } from './Map'
import { Snake } from './Snake'
import { Timer } from './Timer'
import { Food } from './Food'
import { ControllerKeyCode } from '../../layout/enums'
import { IGameService } from '../../layout/interface/IGameService'

export class GameServiceImpl implements IGameService{
    map: Map

    private snake: Snake
    private timer: Timer
    constructor(){
        const config = new Config()// init config
        this.map = reactive(new Map(config))// init map
        this.snake = new Snake(this.map)// init snake
        const food = new Food(this.map)// init food
        this.timer = new Timer(config, this.snake, food)// init timer
    }
    pause(): void {
        this.timer.pause()
    }
    move(eventCode: string): void {
        this.snake.control(eventCode as ControllerKeyCode)
    }
    start(): void {
        this.timer.start()
    }
}